<template>
  <div>
    <h1>list</h1>
    <button @click="sendDataToParent">向父组件发送数据</button>
    <button @click="destroyList">卸载list组件</button>
  </div>
</template>

<script>
export default {
  name: "List",
  data() {
    return {
      list: [
        { name: "xiaoming", age: 18 },
        { name: "xiaowang", age: 19 },
        { name: "xiaoli", age: 20 },
      ],
    };
  },
  methods: {
    sendDataToParent() {
        //this.$emit触发当前实例上的自定义事件,附加参数都会传给监听器回调
      this.$emit("atguigu", this.list);
    },
    destroyList(){
        //卸载list组件
        this.$destroy()
    }
  },

  beforeDestroy(){
    /* 
    真正的解绑:
        是在绑定自定义事件的子组件件中卸载调用自定义事件
    */
    this.$off('atguigu')
  }
};
</script>

<style>
</style>